Skip to content

Fix DomCrawler html dumping example. #2309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 30, 2013
Merged

Fix DomCrawler html dumping example. #2309

merged 2 commits into from
Mar 30, 2013

Conversation

pvolok
Copy link
Contributor

@pvolok pvolok commented Mar 14, 2013

Current example collects HTML of the whole documents instead of required nodes.

Q A
Doc fix? yes
New docs? no
Applies to 2.0+
Fixed tickets -

@@ -190,7 +190,7 @@ and :phpclass:`DOMNode` objects:
$html = '';

foreach ($crawler as $domElement) {
$html.= $domElement->ownerDocument->saveHTML();
$html.= $domElement->ownerDocument->saveHTML($domElement);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while it is not your mistake, could you please add a space between $html and .=?

@wouterj
Copy link
Member

wouterj commented Mar 14, 2013

👍

@pvolok
Copy link
Contributor Author

pvolok commented Mar 14, 2013

Done.

@wouterj
Copy link
Member

wouterj commented Mar 22, 2013

Some more research turned out that this sidebar give us an example on how to get the HTML of the complete Crawler, not a single element. So I changed my mind into a 👎 on this change. @weaverryan what do you think?

@pvolok
Copy link
Contributor Author

pvolok commented Mar 25, 2013

I'm not sure that you got it correctly. Here is an example where the crawler represents all b tags in the document. Current doc example outputs the whole document twice (like we didn't filter the crawler). After my fix it prints 2 b tags.

use Symfony\Component\DomCrawler\Crawler;

$crawler = new Crawler('<b>1</b><i>2</i><b>3</b>');

$html = '';
foreach ($crawler->filter('b') as $domElement) {
    $html.= $domElement->ownerDocument->saveHTML();
}
echo $html;
<_root><html><body><b>1</b><i>2</i><b>3</b></body></html></_root>
<_root><html><body><b>1</b><i>2</i><b>3</b></body></html></_root>
use Symfony\Component\DomCrawler\Crawler;

$crawler = new Crawler('<b>1</b><i>2</i><b>3</b>');

$html = '';
foreach ($crawler->filter('b') as $domElement) {
    $html .= $domElement->ownerDocument->saveHTML($domElement);
}
echo $html;
<b>1</b><b>3</b>

@wouterj
Copy link
Member

wouterj commented Mar 25, 2013

Ah, I understand what you mean. You're correct. 👍

weaverryan added a commit that referenced this pull request Mar 30, 2013
Fix DomCrawler html dumping example.
@weaverryan weaverryan merged commit 9afb147 into symfony:2.0 Mar 30, 2013
@weaverryan
Copy link
Member

Awesome guys, thanks!

@pvolok pvolok deleted the fix_domcrawler_example branch March 30, 2013 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants